home *** CD-ROM | disk | FTP | other *** search
- Path: chronicle.mti.sgi.com!austern
- From: James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de>
- Newsgroups: comp.std.c++
- Subject: Re: The realloc question: rationale?
- Date: 26 Feb 1996 11:48:32 PST
- Organization: -
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <9602261740.AA28201@lts.sel.alcatel.de>
- References: <4g903m$7g8@mari.onr.com> <4gl2ad$lqi@hermes.synopsys.com> <31301BFE.450A@onr.com> <xsod973w4m5.fsf@glob.cs.rpi.edu>
- NNTP-Posting-Host: isolde.mti.sgi.com
- X-Original-Date: Mon, 26 Feb 96 18:40:08 +0100
- In-Reply-To: vandevod@cs.rpi.edu's message of 26 Feb 1996 01:33:33 GMT
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMTIOpUy4NqrwXLNJAQG8mwH/Qr2+pincVvpog44bxi2ngO8ycJ6S9Il5
- MQeEaRtK7pZl8gvhNWydFi1p489OFMDaTmP2ZTML9HR7yjrDAZ70zw==
- =gs+6
- Originator: austern@isolde.mti.sgi.com
-
- In article <xsod973w4m5.fsf@glob.cs.rpi.edu> vandevod@cs.rpi.edu
- (David Vandevoorde) writes:
-
- |> >>>>> "KK" == Kerry Kimbrough <kk@onr.com> writes:
- |> KK> Joe Buck wrote:
- |> KK>> You can, of course, call the C realloc().
-
- |> KK> But then crash? My understanding is that mixture of alloc/free and
- |> KK> friends with new/delete is not guaranteed to be valid and
- |> KK> therefore is discouraged. Not true?
- |> [...]
-
- |> Since you can provide your own new operators etc., you can ensure that
- |> it's safe to use realloc with new/delete (or you can provide a function
- |> based on realloc with similar functionality).
-
- I don't think you can make it safe even providing your own operator
- new/delete (or rather operator new[]/delete[], since realloc only
- makes sense on arrays). There are two problems:
-
- 1. It is, in fact, impossible to obtain the address actually returned
- by operator new[]. The implementation is allowed to (and most do) ask
- for extra memory in order to maintain the number of elements.
- Typically, this memory will be in front of the first element, so the
- compiler will `fix up' the address returned by operator new[] before
- you ever see it.
-
- 2. The implementation is allowed to save this address in some sort of
- cache. For example, an alternate implementation of a new expression
- for an array would be for the implementation to maintain an
- associative array of addresses to counts.
-
- --
- James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
- GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
- Conseils, Θtudes et rΘalisations en logiciel orientΘ objet --
- -- A la recherche d'une activitΘ dans une region francophone
- ---
- [ comp.std.c++ is moderated. To submit articles: Try just posting with your
- newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
- comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
- Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-